import time
from .celery import cel
import subprocess
import redis

rdp = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
r = redis.StrictRedis(connection_pool=rdp)


@cel.task
def synchronize_code(task_id):
    if not subprocess.call(['ansible', 'all', '-u', 'root', '-a', '/bin/sh /root/boss.sh']):
        r.rpush(task_id, '2')
    else:
        r.rpush(task_id, '3')
    return 200


@cel.task
def synchronize_data(task_id):
    time.sleep(3)
    r.rpush(task_id, '2')
    return 200


@cel.task
def compute_salary(task_id):
    time.sleep(3)
    r.rpush(task_id, '2')
    return 200
